<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: X_REQUESTED_WITH,TOKEN');
define('APP_PATH',dirname(__FILE__).DS);
define('CONFIG_PATH',APP_PATH.DS.'config'.DS);
define('FUN_PATH',APP_PATH.DS.'function'.DS);
define('LIB_PATH',APP_PATH.DS.'lib'.DS);
//缓存文件夹地址
define('CACHE_PATH', SITE_PATH.'caches'.DS);

//当前访问的主机名
define('SITE_URL', (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ''));
//来源
define('REFERER', isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '');

define('NOW',      $_SERVER['REQUEST_TIME']);
define('IS_GET',   $_SERVER['REQUEST_METHOD'] =='GET' ? true : false);
define('IS_POST',  $_SERVER['REQUEST_METHOD'] =='POST' ? true : false);
define('IS_AJAX',  (isset($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') ? true : false);

//加载项目公共函数库
if(is_file(FUN_PATH.'global.php')) {
    include FUN_PATH.'global.php';
}
//加载项目公共配置文件
if(is_file(CONFIG_PATH.'config.php')) {
    C(include CONFIG_PATH.'config.php');
}
spl_autoload_register('loader');
set_exception_handler(array('Debug','Exception'));//定义异常处理器

if(DEBUG){
    ini_set("display_errors", "On");
    error_reporting(E_ERROR | E_WARNING | E_PARSE);
    //error_reporting(E_ALL);
}else{
    register_shutdown_function(array('Debug','shutDown'));//捕获系统致命错误
    set_error_handler(array('Debug','appError'));//定义错误处理器
}

// 设置系统时区
function_exists('date_default_timezone_set') && date_default_timezone_set(C('DEFAULT_TIMEZONE'));

header('Content-type: text/html; charset='.C('CHARSET'));
if(isset($_SERVER['HTTP_TOKEN'])&&$_SERVER['HTTP_TOKEN']!=''){
    session_id(trim($_SERVER['HTTP_TOKEN']));  
}
ini_set('session.cookie_path','/');
session_start();